package com.study.myThreadLocal;

import java.util.concurrent.Callable;

/**
 * @description:
 * @author: 汤凌宇
 * @time: 2021/6/24 22:11
 */
public class BizTask<T> implements Callable<T> {
    private String session = null;

    public BizTask(String session) {
        this.session = session;
    }

    @Override
    public T call(){
        try {
            ContextHolder.set(this.session);
            // 执行业务逻辑
        } catch(Exception e){
            //log error
        } finally {
            ContextHolder.remove(); // 清理 ThreadLocal 的上下文，避免线程复用时context互串
        }
        return null;
    }

    public static void main(String[] args) {
        
    }
}
